home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994…tember: Reference Library / Dev.CD Sep 94.toast / Periodicals / develop / develop Issue 6 / develop 6 code / TCP / NewsWatcher / NewsWatcher 2.0d15 source / source / newswatcher.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  4.7 KB  |  215 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     NewsWatcher - Macintosh Network News Reader.
  4.     
  5.     Portions copyright © 1990, Apple Computer.
  6.     Portions copyright © 1993, Northwestern University.
  7.  
  8. ------------------------------------------------------------------------------
  9.  
  10.     newswatcher.c
  11.  
  12.     This module contains the main entry point of the program
  13.     and the main event loop.
  14. ----------------------------------------------------------------------------*/
  15.  
  16. #include <string.h>
  17. #include <appleevents.h>
  18.  
  19. #include "glob.h"
  20. #include "activate.h"
  21. #include "close.h"
  22. #include "collapse.h"
  23. #include "draw.h"
  24. #include "init.h"
  25. #include "key.h"
  26. #include "mark.h"
  27. #include "menus.h"
  28. #include "mouse.h"
  29. #include "newart.h"
  30. #include "nntp.h"
  31. #include "prefs.h"
  32. #include "print.h"
  33. #include "util.h"
  34. #include "log.h"
  35. #include "killfile.h"
  36.  
  37.  
  38. /*    FixCursor sets up the type of cursor needed, depending on where the mouse
  39.     pointer is located.  This routine is called in conjunction with WaitNextEvent.
  40. */
  41.  
  42. static void FixCursor (Point mouse, RgnHandle region)
  43. {
  44.     WindowPtr wind;
  45.     RgnHandle arrowRgn,iBeamRgn;
  46.     Rect iBeamRect;
  47.     Point topLeftPt,botRightPt;
  48.     TWindow **info;
  49.     EWindowKind kind;
  50.     TEHandle theTE;
  51.     
  52.     wind = FrontWindow();
  53.     if (!gInBackground && !IsDAWindow(wind)) {
  54.         arrowRgn = NewRgn();
  55.         iBeamRgn = NewRgn();
  56.         SetRectRgn(arrowRgn,-32768,-32768,32767,32767);
  57.         if (IsAppWindow(wind)) {
  58.             info = (TWindow**)GetWRefCon(wind);
  59.             kind = (**info).kind;
  60.             if (kind == kArticle || kind == kMiscArticle ||
  61.                 kind == kPostMessage || kind == kMailMessage) 
  62.             {
  63.                 theTE = (**info).theTE;
  64.                 iBeamRect = (**theTE).viewRect;
  65.                 SetPort(wind);
  66.                 SetPt(&topLeftPt,iBeamRect.left,iBeamRect.top);
  67.                 SetPt(&botRightPt,iBeamRect.right,iBeamRect.bottom);
  68.                 LocalToGlobal(&topLeftPt);
  69.                 LocalToGlobal(&botRightPt);
  70.                 iBeamRect.left = topLeftPt.h;
  71.                 iBeamRect.top = topLeftPt.v;
  72.                 iBeamRect.right = botRightPt.h;
  73.                 iBeamRect.bottom = botRightPt.v;
  74.                 RectRgn(iBeamRgn,&iBeamRect);
  75. /*                SetOrigin(-wind->portBits.bounds.left, -wind->portBits.bounds.top);*/
  76. /*                SectRgn(iBeamRgn, wind->visRgn, iBeamRgn);*/
  77. /*                SetOrigin(0,0);*/
  78.             }
  79.         }
  80.         DiffRgn(arrowRgn,iBeamRgn,arrowRgn);
  81.         if (PtInRgn(mouse,iBeamRgn)) {
  82.             SetCursor(&gIBeamCurs);
  83.             CopyRgn(iBeamRgn,region);
  84.         } else {
  85.             SetCursor(&qd.arrow);
  86.             CopyRgn(arrowRgn,region);
  87.         }
  88.         DisposeRgn(arrowRgn);
  89.         DisposeRgn(iBeamRgn);
  90.     }
  91. }
  92.  
  93.  
  94. /*    DoQuit closes windows prior to the quitting of the application.
  95. */
  96.  
  97. static Boolean DoQuit (void)
  98. {
  99.     WindowPtr wind;
  100.     TWindow **info;
  101.     
  102.     while (true) {
  103.         wind = FrontWindow();
  104.         while (wind && (wind == gFullGroupWindow || 
  105.             !IsAppWindow(wind) || IsStatusWindow(wind)))
  106.             wind = (WindowPtr)((WindowPeek)wind)->nextWindow;
  107.         if (wind == nil) break;
  108.         if (!DoCloseWindow(wind)) return false;
  109.     }
  110.     if (gFullGroupWindow != nil) DoCloseWindow(gFullGroupWindow);
  111.     return true;
  112. }
  113.  
  114.  
  115.  
  116. /* MainEvent - main event loop. */
  117.  
  118. static void MainEvent (void)
  119. {
  120.     EventRecord ev;
  121.     RgnHandle cursorRgn;
  122.     Boolean    gotEvt;
  123.     WindowPtr wind;
  124.     TWindow **info;
  125.     EWindowKind kind;
  126.  
  127.     cursorRgn = NewRgn();
  128.  
  129.     while (!gDone) {
  130.     
  131.         gCancel = false;
  132.         
  133.         wind = FrontWindow();
  134.         if (IsStatusWindow(wind)) {
  135.             CloseStatusWindow();
  136.         } else if (IsAppWindow(wind)) {
  137.             info = (TWindow**)GetWRefCon(wind);
  138.             kind = (**info).kind;
  139.             if (kind == kArticle || kind == kMiscArticle  ||
  140.                 kind == kPostMessage || kind == kMailMessage)
  141.                 TEIdle((**info).theTE);
  142.         }
  143.         
  144.         AdjustMenus();
  145.         
  146.         CloseIdleNewsConnection(false);
  147.             
  148.         gotEvt = WaitNextEvent(everyEvent,&ev,GetCaretTime(),cursorRgn);
  149.         
  150.         FixCursor(ev.where,cursorRgn);
  151.         
  152.         if (gotEvt) {
  153.             switch (ev.what) {
  154.                 case mouseDown:
  155.                     HandleMouseDown(&ev);
  156.                     break;
  157.                 case keyDown:
  158.                 case autoKey:
  159.                     HandleKeyDown(wind, &ev);
  160.                     break;
  161.                 case activateEvt:
  162.                     HandleActivate((WindowPtr)ev.message,
  163.                         ((ev.modifiers & activeFlag) != 0)); 
  164.                     break;
  165.                 case updateEvt:
  166.                     HandleUpdate((WindowPtr)(ev.message));
  167.                     break;
  168.                 case app4Evt:
  169.                     HandleSuspendResume(ev.message);
  170.                     break;
  171.                 case kHighLevelEvent:
  172.                     AEProcessAppleEvent(&ev);
  173.                     break;
  174.             }
  175.             FixCursor(ev.where,cursorRgn);
  176.         }
  177.         
  178.         if (gDone) gDone = DoQuit();
  179.     }
  180.     
  181.     DisposeRgn(cursorRgn);
  182.         
  183.     CloseIdleNewsConnection(true);
  184.     
  185.     EndNNTP();
  186.     WritePrefs();
  187.     
  188.     if (gPrefs.logActionsToFile) CloseLogFile();
  189.     
  190.     #ifdef FILTERS
  191.         WriteKillFile();
  192.     #endif
  193.  
  194.     memset(gPrefs.remotePassword,'%', sizeof(gPrefs.remotePassword));
  195.     memset(gAutoFetchPass,'%', sizeof(gAutoFetchPass));
  196. }
  197.  
  198.  
  199. /* main - main entry point. */
  200.  
  201. void main (void)
  202. {
  203.     SetApplLimit(GetApplLimit() - 20000);
  204.     MaxApplZone();
  205.     MoreMasters();
  206.     MoreMasters();
  207.     MoreMasters();
  208.     MoreMasters();
  209.     MoreMasters();
  210.     Init();
  211.     UnloadSeg(Init);
  212.     MainEvent();
  213.     ExitToShell();    /* Yes, you really do need to do this! */
  214. }
  215.